const {BrowserWindow, Menu} = require('electron')

/**
 * 创建主窗口
 */
function createMainWindow() {
    // Create the browser window.
    Menu.setApplicationMenu(null)
    const mainWindow = new BrowserWindow({
        width: 800,
        height: 600,
        title: "保护你的眼睛",
        backgroundColor: "#424c50",
        show: false,
    })

    // and load the index.html of the app.
    mainWindow.loadFile('index.html')
    mainWindow.once('ready-to-show', () => {
        mainWindow.show()
    })

    // Open the DevTools.
    // mainWindow.webContents.openDevTools()
}

/**
 * 打开请作者喝咖啡页面
 */
function openCoffee() {
    const coffeeWin = new BrowserWindow({
        width: 400,
        height: 560,
        show: false,
    })
    coffeeWin.loadFile("coffee.html")
    coffeeWin.once("ready-to-show", () => coffeeWin.show())
}

/**
 * 创建休息弹窗
 * @return Electron.BrowserWindow
 */
function createRest() {
    let bg = process.platform === "darwin" ? null : "#424c50"
    let window = new BrowserWindow({
            width: 500,
            height: 500,
            simpleFullscreen: true,
            fullscreen: true,
            vibrancy: 'dark', // 模糊背景效果
            visualEffectState: "active",
            transparent: process.platform === "darwin",
            backgroundColor: bg,
            frame: false,
            show: false,
            webPreferences: {
                nodeIntegration: true,
                contextIsolation: false
            },
        }
    )
    window.loadFile("reset.html").then(r => null);
    window.once("ready-to-show", () => window.show())
    return window;
}

exports.createMainWindow = createMainWindow
exports.openCoffee = openCoffee
exports.createRest = createRest